<?php

/**
 * 初中生成绩统计
 * 
 * @version 1.0
 * @date 2013-12-31
 */
class DefaultController extends FController {

    public $user_school_list;
    public $user_subject_list;
    public $user_role_list;
    public $exam_id;
    public function accessRules() {
        $config = array(
            'index' => 1
        );
        return ZRole::auth("st", $config);
    }

    public function __common() {
        parent::init();
        if (empty($this->cLoginUser)) {
            $this->redirect($this->createUrl('/site/login'));
        } else {
            $userLoginUser = $this->cLoginUser;
            $this->user_role_list = isset($userLoginUser['cuser']['role_id']) ? $userLoginUser['cuser']['role_id'] : '';
            $this->user_school_list = isset($userLoginUser['cuser']['school']['school_id']) ? $userLoginUser['cuser']['school']['school_id'] : '';
            $this->user_subject_list = isset($userLoginUser['cuser']['school']['subject_id']) ? $userLoginUser['cuser']['school']['subject_id'] : '';
            $zRow = new ZRole();
            //得到学校对应的考试
            $exam_list = $zRow->_getSchoolExam($this->user_school_list);
            if (!empty($exam_list)) {
                $this->exam_id = implode(',', $exam_list);
            }
        }

        $this->commonScript();
        Yii::app()->clientScript->registerCssFile(THEME_CSS_URL . '/module_Sip.css');
    }

    /**
     * 初中成绩统计
     * 
     * @version 1.0
     * @date 2013-12-31
     */
    public function actionMscorestaindex() {
        $this->__common();

        $zExam = new zExam();
        $examArray = $zExam->_getExamObject($this->exam_id, $this->user_role_list);

        $this->title = '(初中)成绩统计';
        $this->render('mscoresta_index', array(
            'examArray' => $examArray
        ));
    }
    
    /**
     * 初中分数统计
     * 
     * @version 1.0
     * @date 2014-01-23
     */
    public function actionMscorelist() {

        $this->__common();
        $this->layout = "//layouts/main_other";
        
        Yii::app()->clientScript->registerCssFile(THEME_CSS_URL . '/chart.css');
        Yii::app()->clientScript->registerScriptFile(STATICS_URL . "/js/Highcharts/js/highcharts.js");
        Yii::app()->clientScript->registerScriptFile(STATICS_URL . "/js/Highcharts/js/modules/exporting.js");
        Yii::app()->clientScript->registerScriptFile(THEME_JS_URL . "/chart.js");

        // request 参数
        $exam_id = $this->request->getParam('exam_id');
        $school_id = $this->request->getParam('school_code');

        //得到考试项目学校
        $zEdu = new ZEdu();
        $subjectObject = $zEdu->_getSubjectObject();
        $subject_oArray = array();  //代码对应的科目
        foreach($subjectObject as $sVal){
            $subject_oArray[$sVal['subject_code']] = $sVal;
        }
        $schoolObject = $zEdu->_getSchoolObject();
        
        $zExam = new zExam();
        
        $exam_array = $zExam->_getExamInfo($exam_id);
        $exam_subject_array = $exam_subject = array();
        if(!empty($exam_array)){  //得到考试科目
            $subject_ids = $exam_array['exam_subject_ids'];
            if(!empty($subject_ids)){
                $sArray = explode('-', $subject_ids);
                foreach($sArray as $sV){
                    $exam_subject_array[] = isset($subject_oArray[$sV])?$subject_oArray[$sV]:'';
                }
                $exam_subject = self::_getDBnum($exam_subject_array);
            }
        }
        $table1 = $table2 = $table3 = $table6 = $table7 = "";
               
        $scoreStd = $zExam->_getCzSubject($exam_id); //得到科目及格率 优秀/及格/低分 下线
        
        $photo_image_data = array();
        
        $pj_array = $yx_array = $jg_array = $df_array = $s_array = $dataNum = $photo_dataNum_data = array(); //图表数据
        $photo_dataNum_data['pj_photo'] = $photo_dataNum_data['yx_photo'] = $photo_dataNum_data['jg_photo'] = $photo_dataNum_data['df_photo'] = array();
        $pj_pnum = $yx_pnum = $jg_pnum = $df_pnum = array();
        $new_subject_array = array();
        // 考试科目人数及分数统计
        if ($this->user_role_list != 1) {
            $scoreRows = $zExam->_getCzNewPoint($exam_id, $school_id, $scoreStd, $exam_subject,$this->user_school_list);
        }else {
            $scoreRows = $zExam->_getCzNewPoint($exam_id, $school_id, $scoreStd, $exam_subject);
        }
        
        $totalNum = $totalPoint = $totalyxPeople = $totaljgPeople = $totaldfPeople = 0;
        $totalSubPoint = $totalSubYx = $totalSubJg = $totalSubdf = array();
        if ($scoreRows) {
            $i=0;
            $school_point_all = $school_num_all = $school_ay1 = $school_aj1 = $school_ad1 = 0;  //总分汇总
            
            $school_subject_all = array();
            foreach ($scoreRows as $key => $value) {
                
                $table4 = '';
                $photo_pj_data = $photo_yx_data = $photo_jg_data = $photo_df_data = array(); //图表学校信息
                $schoolName = isset($schoolObject[$key])?$schoolObject[$key]:'';  //图表学校信息
                $all_people = $value['people'];  //学校总人数

                
                //得到总平均分
                $avgPoint = ($all_people > 0) ? sprintf('%.2f', $value['point'] / $all_people) : 0;
                

                $ayxl = $ajgl = $adfl = 0;
                $ayl = $ajl = $adl = 0;
                $schoolAllPoint = 0;
                    
                if(!empty($exam_subject_array)){
                    $pj_photo = $yx_photo = $jg_photo = $df_photo = array();//图表显示数据
                    $pki=0;
                    foreach($exam_subject_array as $sKey => $sVal){
                        if(!empty($sVal)){
                            //得到单科平均分
                        $sPoint = isset($value['subject'][$sVal['subject_id']])?$value['subject'][$sVal['subject_id']]:0;

                        $savgPoint = ($all_people > 0) ? sprintf('%.2f', $sPoint / $all_people) : 0;


                       
                        //单科优秀率
                        $yx = isset($value[$sVal['subject_id']]['type1']) ? $value[$sVal['subject_id']]['type1'] : 0;
                            $yxl = ($all_people > 0) ? sprintf('%.2f', ($yx / $all_people)*100) : 0;
                        
                        //单科及格率
                        $jg = isset($value[$sVal['subject_id']]['type2']) ? $value[$sVal['subject_id']]['type2'] : 0;
                            $jgl = ($all_people > 0) ? sprintf('%.2f', ($jg / $all_people)*100) : 0;
                        
                        //单科低分率
                        $df = isset($value[$sVal['subject_id']]['type3']) ? $value[$sVal['subject_id']]['type3'] : 0;
                            $dfl = ($all_people > 0) ? sprintf('%.2f', ($df / $all_people)*100) : 0;
                        
                        if($i==0){
                            $subjectName = $sVal['subject_name'];
                            $table1 .= '<th width="200" align="center" colspan="4" valign="middle" class="border_d">
                               <span style="padding:0 5px;">' . $subjectName . '</span></th>';
                        $table2 .= '<th align="center" class="border_d" valign="middle" width="50"><span style="padding:0 5px;">平均分</span></th>
                                    <th align="center" class="border_d" valign="middle" width="50"><span style="padding:0 5px;">优秀率</span></th>
                                    <th align="center" class="border_d" valign="middle" width="50"><span style="padding:0 5px;">及格率</span></th>
                                    <th align="center" class="border_d" valign="middle" width="50"><span style="padding:0 5px;">低分率</span></th>';
                        }                   
                            
                            $dataNum['pj_photo'][$pki][] = (float)$savgPoint;  //科目图表的详细信息
                            $dataNum['yx_photo'][$pki][] = (float)$yxl;
                            $dataNum['jg_photo'][$pki][] = (float)$jgl;
                            $dataNum['df_photo'][$pki][] = (float)$dfl;
                            $pki++;
                            $new_subject_array['subject_total'][$key][$sVal['subject_id']]['pj'] = $savgPoint;  //汇总分数(学校单科目的汇总)
                            $new_subject_array['subject_total'][$key][$sVal['subject_id']]['yx'] = $yxl;
                            $new_subject_array['subject_total'][$key][$sVal['subject_id']]['jg'] = $jgl;
                            $new_subject_array['subject_total'][$key][$sVal['subject_id']]['df'] = $dfl;
                            
                            //单科汇总(最底部)
                            if(!isset($totalSubYx[$sVal['subject_id']])){
                                $totalSubYx[$sVal['subject_id']] = 0;
                            }
                            if(!isset($totalSubJg[$sVal['subject_id']])){
                                $totalSubJg[$sVal['subject_id']] = 0;
                            }
                            if(!isset($totalSubdf[$sVal['subject_id']])){
                                $totalSubdf[$sVal['subject_id']] = 0;
                            }
                            $totalSubYx[$sVal['subject_id']] += $yx;
                            $totalSubJg[$sVal['subject_id']] += $jg;
                            $totalSubdf[$sVal['subject_id']] += $df;
                            }
                        }
                    }
                    
                //单科总分（最底部)
                if(!empty($value['subject'])){
                    foreach($value['subject'] as $subKey => $subVal){
                        if(!isset($totalSubPoint[$subKey])){
                            $totalSubPoint[$subKey] = 0;
                        }
                        $totalSubPoint[$subKey] += $subVal;
                    }
                }
                //得到当个学校汇总数据（最左侧）
                if (isset($value['student']) && !empty($value['student'])) {
                    $pType = isset($scoreStd['point']) ? $scoreStd['point'] : array();
                    if(!empty($pType)){
                        foreach ($value['student'] as $pValue) {
                            $type = $zExam->_getPointType($pType,$pValue);
                            switch ($type){
                                case 1:
                                    $ayxl += 1;  //优秀
                                    $ajgl += 1;  //及格
                                    break;
                                case 2:
                                    $ajgl += 1;  //及格
                                    break;
                                case 3:
                                    $adfl += 1; //低分
                                    break;
                            } 
                        }
                    }
                    $ayl = ($all_people > 0) ? sprintf('%.2f', $ayxl / $all_people * 100) : 0;
                    $ajl = ($all_people > 0) ? sprintf('%.2f', $ajgl / $all_people * 100) : 0;
                    $adl = ($all_people > 0) ? sprintf('%.2f',$adfl / $all_people * 100) : 0;
                }

                //得到全学校汇总(最底部)
                $totalNum += $all_people;   //总人数
                $totalPoint += $value['point'];
                $totalyxPeople += $ayxl;
                $totaljgPeople += $ajgl;
                $totaldfPeople += $adfl;
                $pj_dataNum[] = (float) $avgPoint;  //图表显示数据      
                $yx_dataNum[] = (float) $ayl;
                $jg_dataNum[] = (float) $ajl;
                $df_dataNum[] = (float) $adl;
                $s_array[] = $schoolName;  //图表显示学校
                
                $i++;
                $new_subject_array['total'][$key]['people'] = $all_people;
                $new_subject_array['total'][$key]['pj'] = $avgPoint;  //汇总各学校总分
                $new_subject_array['total'][$key]['yx'] = $ayl;
                $new_subject_array['total'][$key]['jg'] = $ajl;
                $new_subject_array['total'][$key]['df'] = $adl;
            }
            //总分汇总 合计
            $school_avgPoint = ($totalNum > 0) ? sprintf('%.2f', $totalPoint / $totalNum) : 0;
            $s_ay1 = sprintf('%.2f', $totalyxPeople / $totalNum * 100);
            $s_aj1 = sprintf('%.2f', $totaljgPeople / $totalNum * 100);
            $s_ad1 = sprintf('%.2f', $totaldfPeople / $totalNum * 100);
            $subject_total_array = array();
            if (!empty($exam_subject_array)) { //单独科目的总分
                foreach ($exam_subject_array as $sKey => $sVal) {
                    $apjf = isset($totalSubPoint[$sVal['subject_id']]) ? $totalSubPoint[$sVal['subject_id']] : 0;
                    $apj = sprintf('%.2f', $apjf / $totalNum);
                    $ayxf = isset($totalSubYx[$sVal['subject_id']]) ? $totalSubYx[$sVal['subject_id']] : 0;
                    $ayx = sprintf('%.2f', $ayxf / $totalNum * 100);
                    $ajgf = isset($totalSubJg[$sVal['subject_id']]) ? $totalSubJg[$sVal['subject_id']] : 0;
                    $ajg = sprintf('%.2f', $ajgf / $totalNum * 100);
                    $adff = isset($totalSubdf[$sVal['subject_id']]) ? $totalSubdf[$sVal['subject_id']] : 0;
                    $adf = sprintf('%.2f', $adff / $totalNum * 100);
                    $subject_total_array[$sVal['subject_id']]['pj'] = $apj;
                    $subject_total_array[$sVal['subject_id']]['yx'] = $ayx;
                    $subject_total_array[$sVal['subject_id']]['jg'] = $ajg;
                    $subject_total_array[$sVal['subject_id']]['df'] = $adf;
                    $table7 .= '<td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $apj . '</span></td>
                                <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $ayx . '%</span></td>
                                <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $ajg . '%</span></td>
                                <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $adf . '%</span></td>';
                }
            }
            $table6 = '<tr height="38">
                    <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">合计</span></td>
                    <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' .$totalNum. '</span></td>
                    <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' .$school_avgPoint. '</span></td>
                    <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' .$s_ay1. '%</span></td>
                    <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' .$s_aj1. '%</span></td>
                    <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' .$s_ad1. '%</span></td>' .$table7. '</tr>';
            $table3 = '';
            if(isset($new_subject_array['total'])){//单科成绩输出
                foreach($new_subject_array['total'] as $key => $value){
                    $people = isset($value['people']) ? $value['people'] : 0;
                    $zpj = isset($value['pj']) ? $value['pj'] : 0;
                    $zyx = isset($value['yx']) ? $value['yx'] : 0;
                    $zjg = isset($value['jg']) ? $value['jg'] : 0;
                    $zdf = isset($value['df']) ? $value['df'] : 0;
                    $table4 = $table5 = '';
                    $subject_array = isset($new_subject_array['subject_total'][$key]) ? $new_subject_array['subject_total'][$key] : array();
                    if(!empty($subject_array)){
                        foreach($subject_array as $sKey => $sValue){
                            $spj = isset($sValue['pj']) ? $sValue['pj'] : 0;
                            $syx = isset($sValue['yx']) ? $sValue['yx'] : 0;
                            $sjg = isset($sValue['jg']) ? $sValue['jg'] : 0;
                            $sdf = isset($sValue['df']) ? $sValue['df'] : 0;
                            $table4 .= '<td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $spj . '</span></td>
                                            <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $syx . '%</span></td>
                                            <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $sjg . '%</span></td>
                                            <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $sdf . '%</span></td>';
                            $zspj = isset($subject_total_array[$sKey]['pj']) ? $subject_total_array[$sKey]['pj'] : 0;
                            $zsyx = isset($subject_total_array[$sKey]['yx']) ? $subject_total_array[$sKey]['yx'] : 0;
                            $zsjg = isset($subject_total_array[$sKey]['jg']) ? $subject_total_array[$sKey]['jg'] : 0;
                            $zsdf = isset($subject_total_array[$sKey]['df']) ? $subject_total_array[$sKey]['df'] : 0;
                            $cspj = sprintf('%.2f', (float)$spj-(float)$zspj);
                            $csyx = sprintf('%.2f', (float)$syx-(float)$zsyx);
                            $csjg = sprintf('%.2f', (float)$sjg-(float)$zsjg);
                            $csdf = sprintf('%.2f', (float)$sdf-(float)$zsdf);
                            $table5 .= '<td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $cspj . '</span></td>
                                            <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $csyx . '%</span></td>
                                            <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $csjg . '%</span></td>
                                            <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $csdf . '%</span></td>';
                        }
                    }
                    $table3 .= '<tr height="38">
                                <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $schoolObject[$key] . '</span></td>
                                <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $people . '</span></td>
                                <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $zpj . '</span></td>
                                <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $zyx . '%</span></td>
                                <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $zjg . '%</span></td>
                                <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' . $zdf . '%</span></td>' .$table4. '</tr>';
                   $cpj = sprintf('%.2f', (float)$zpj - (float)$school_avgPoint);
                   $cyx = sprintf('%.2f', (float)$zyx - (float)$s_ay1);
                   $cjg = sprintf('%.2f', (float)$zjg - (float)$s_aj1);
                   $cdf = sprintf('%.2f', (float)$zdf - (float)$s_ad1);
                   $table3 .= '<tr height="38">
                                <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;"></span></td>
                                <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;"></span></td>
                                <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' .$cpj. '</span></td>
                                <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' .$cyx. '%</span></td>
                                <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' .$cjg. '%</span></td>
                                <td align="center" class="border_d" valign="middle" width="100"><span style="padding:0 5px;">' .$cdf. '%</span></td>' .$table5. '</tr>';
                }
            }
            $table3 .= $table6;
            //图形显示数据
            $pj_p = $yx_p = $jg_p = $df_p = array();
            $pj_p[] = $pj_dataNum;
            $yx_p[] = $yx_dataNum;
            $jg_p[] = $jg_dataNum;
            $df_p[] = $df_dataNum;
            $pj_pnum = array_merge_recursive($pj_p,$dataNum['pj_photo']);
            $photo_dataNum_data['pj_photo'] = $pj_pnum;
            $yx_pnum = array_merge_recursive($yx_p,$dataNum['yx_photo']);
            $photo_dataNum_data['yx_photo'] = $yx_pnum;
            $jg_pnum = array_merge_recursive($jg_p,$dataNum['jg_photo']);
            $photo_dataNum_data['jg_photo'] = $jg_pnum;
            $df_pnum = array_merge_recursive($df_p,$dataNum['df_photo']);
            $photo_dataNum_data['df_photo'] = $df_pnum;
            $pj_array['unit'] = $yx_array['unit'] = $jg_array['unit'] = $df_array['unit'] = '分';  //图表显示数据
            $pj_array['lable'] = '平均分';
            $yx_array['lable'] = 'yx率';
            $jg_array['lable'] = '及格率';
            $df_array['lable'] = '低分率';
            $pj_array['columnTipData'] = $yx_array['columnTipData'] = $jg_array['columnTipData'] = $df_array['columnTipData'] = array();
            $pj_array['categories'] = $yx_array['categories'] = $jg_array['categories'] = $df_array['categories'] = $s_array;
            $photo_image_data['pj_photo'] = $pj_array;
            $photo_image_data['yx_photo'] = $yx_array;
            $photo_image_data['jg_photo'] = $jg_array;
            $photo_image_data['df_photo'] = $df_array;
        }
        
        
        $this->title = '(初中)成绩统计';
        $this->render("mscoresta_list", array(
            'exam_array'            => $exam_array,
            'table1'                => $table1,
            'table2'                => $table2,
            'table3'                => $table3,
            'photo_image_data'  => $photo_image_data,
            'pj_array'  => $pj_array,
            'yx_array'  => $yx_array,
            'jg_array'  => $jg_array,
            'df_array'  => $df_array,
            'exam_id'           => $exam_id,
            'school_id' => $school_id,
            'photo_dataNum_data' => $photo_dataNum_data,
            'exam_subject_array' =>$exam_subject_array
        ));
    }
    /**
     * 导出优秀率列表
     * 
     * @version 1.0
     * @date 2014-01-25
     */
    public function actionImport_list(){
    	$this->__common();
        $exam_id = $this->request->getParam('exam_id');
        $school_id = $this->request->getParam('school_id');
        if (!empty($exam_id)) {
            //得到考试项目学校
            $zEdu = new ZEdu();
            $subjectObject = $zEdu->_getSubjectObject();
            $subject_oArray = array();  //代码对应的科目
            foreach ($subjectObject as $sVal) {
                $subject_oArray[$sVal['subject_code']] = $sVal;
            }
            $schoolObject = $zEdu->_getSchoolObject();
            $zExam = new zExam();
            $exam_array = $zExam->_getExamInfo($exam_id);
            $exam_subject_array = $exam_subject = array();
            if (!empty($exam_array)) {  //得到考试科目
                $subject_ids = $exam_array['exam_subject_ids'];
                if (!empty($subject_ids)) {
                    $sArray = explode('-', $subject_ids);
                    foreach ($sArray as $sV) {
                        $exam_subject_array[] = isset($subject_oArray[$sV]) ? $subject_oArray[$sV] : '';
                    }
                    $exam_subject = self::_getDBnum($exam_subject_array);
                }
            }
            $table1 = $table2 = $table3 = $table4 = $table6 = $table7 = "";
            $scoreStd = $zExam->_getCzSubject($exam_id); //得到科目及格率 优秀/及格/低分 下线
            $photo_image_data = array();
            $new_subject_array = array();
            $totalNum = $totalPoint = $totalyxPeople = $totaljgPeople = $totaldfPeople = 0;
            $totalSubPoint = $totalSubYx = $totalSubJg = $totalSubdf = array();
            // 考试科目人数及分数统计
	        if ($this->user_role_list != 1) {
                $data = $zExam->_getCzNewPoint($exam_id, $school_id, $scoreStd, $exam_subject,$this->user_school_list);
	        }else {
                $data = $zExam->_getCzNewPoint($exam_id, $school_id, $scoreStd, $exam_subject);
	        }
            if (!empty($data)) {
                spl_autoload_unregister(array('YiiBase', 'autoload'));
                include_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/extensions/PHPExcel.php');
                include_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/extensions/PHPExcel/IOFactory.php');
                $objPHPExcel = new PHPExcel();
                $ktitle = array(0=>'A',1=>'B',2=>'C',3=>'D',4=>'E',5=>'F',6=>'G',7=>'H',8=>'I',9=>'J',10=>'K',11=>'L',12=>'M',13=>'N',14=>'O',15=>'P',16=>'Q',17=>'R',18=>'S',19=>'T',20=>'U',21=>'V',22=>'W',23=>'X',24=>'Y',25=>'Z');
                
                //第一行
                $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue('A1', $exam_array['exam_term_name'])
                        ->setCellValue('C1', '总分');
                $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
                $objPHPExcel->getActiveSheet(0)->mergeCells( 'A1:B1');
                $objPHPExcel->getActiveSheet(0)->mergeCells( 'C1:F1');
                //第二行
                $objPHPExcel->setActiveSheetIndex(0)
                            ->setCellValue('A' . 2, '学校')
                            ->setCellValue('B' . 2, '考试人数')
                            ->setCellValue('C' . 2, '平均分')
                            ->setCellValue('D' . 2, '优秀率')
                            ->setCellValue('E' . 2, '及格率')
                            ->setCellValue('F' . 2, '低分率');
                $list = array();               
                $ii = 3;

                $i_num = 0;
                $school_point_all = $school_num_all = $school_ay1 = $school_aj1 = $school_ad1 = 0;  //总分汇总
                $school_subject_all = $school_subject_key = array();  //科目总分汇总
                foreach($data as $key => $value){
                    $school_name = $schoolObject[$key];
                    $all_people = $value['people'];
                    //得到总平均分
                    $avgPoint = ($all_people > 0) ? sprintf('%.2f', $value['point'] / $all_people) : 0;
                    $ks = $js = 0;       
                    $ayxl = $ajgl = $adfl = 0;
                    $ayl = $ajl = $adl = 0;
                    
                    $i = 6;  //xls数据开始列
                    if (!empty($exam_subject_array)) {
                        foreach ($exam_subject_array as $sk => $subject_value) {
                            if(!empty($subject_value)){
                                //得到单科平均分
                            $sPoint = isset($value['subject'][$subject_value['subject_id']])?$value['subject'][$subject_value['subject_id']]:0;
                            $savgPoint = ($all_people > 0) ? sprintf('%.2f', $sPoint / $all_people) : 0;
                        //单科优秀率
                            $yx = isset($value [$subject_value['subject_id']]['type1']) ? $value[$subject_value['subject_id']]['type1'] : 0;
                                $yxl = ($all_people > 0) ? sprintf('%.2f', $yx / $all_people *100) : 0;
                        //单科及格率
                            $jg = isset($value[$subject_value['subject_id']]['type2']) ? $value[$subject_value['subject_id']]['type2'] : 0;
                                $jgl = ($all_people > 0) ? sprintf('%.2f', $jg / $all_people *100) : 0;
                        //单科低分率
                            $df = isset($value[$subject_value['subject_id']]['type3']) ? $value[$subject_value['subject_id']]['type3'] : 0;
                                $dfl = ($all_people > 0) ? sprintf('%.2f', $df / $all_people *100) : 0;
                                
                        $k = $j = '';
                        $k1 = $k2 = $kl1 = $kl2 = '';
                        $ksnum = 0;
                        if($i==6){
                            $ks = $i+3;  //开始
                            $js = $ks; //结束
                            $k1 = $i+1;
                            $kl1 = self::_getXlsTitle($k1);
                            $k2 = $i+2;
                            $kl2 = self::_getXlsTitle($k2);
                            $ksnum = $i;
                            $k = self::_getXlsTitle($i);
                            $j = self::_getXlsTitle($js);
                            $i = $ks+1;
                        }else{
                            $ks += 1;  //开始
                            $jjs = $ks+3; //结束
                            $k1 = $ks+1;
                            $kl1 = self::_getXlsTitle($k1);
                            $k2 = $ks+2;
                            $kl2 = self::_getXlsTitle($k2);
                            $ksnum = $ks;
                            $k = self::_getXlsTitle($ks);
                            $j = self::_getXlsTitle($jjs);
                            $i = $ks = $ks+3;
                        }
                            
                        if($ii==3){
                                $kst = $k . '1:' . $j . '1';
                                $subjectName = isset($subject_value['subject_name']) ? $subject_value['subject_name'] : '';
                            //第一行开始数据
                                    $objPHPExcel->setActiveSheetIndex(0)->setCellValue($k . 1, $subjectName);
                            //第二行开始数据
                            $objPHPExcel->setActiveSheetIndex(0)
                            ->setCellValue($k . 2, '平均分')
                            ->setCellValue($kl1 . 2, '优秀率')
                            ->setCellValue($kl2 . 2, '及格率')
                            ->setCellValue($j . 2, '低分率');

                        $objPHPExcel->getActiveSheet(0)->mergeCells( $kst );
                            }
                        //第三行开始数据
                        $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue($k . $ii, $savgPoint)
                        ->setCellValue($kl1 . $ii, $yxl)
                        ->setCellValue($kl2 . $ii, $jgl)
                        ->setCellValue($j . $ii, $dfl);
                                
                                $new_subject_array['subject_total'][$key][$subject_value['subject_id']]['pj'] = $savgPoint;  //汇总分数(学校单科目的汇总)
                                $new_subject_array['subject_total'][$key][$subject_value['subject_id']]['yx'] = $yxl;
                                $new_subject_array['subject_total'][$key][$subject_value['subject_id']]['jg'] = $jgl;
                                $new_subject_array['subject_total'][$key][$subject_value['subject_id']]['df'] = $dfl;
                                //单科汇总(最底部)
                                if(!isset($totalSubYx[$subject_value['subject_id']])){
                                    $totalSubYx[$subject_value['subject_id']] = 0;
                    }
                                if(!isset($totalSubJg[$subject_value['subject_id']])){
                                    $totalSubJg[$subject_value['subject_id']] = 0;
                                }
                                if(!isset($totalSubdf[$subject_value['subject_id']])){
                                    $totalSubdf[$subject_value['subject_id']] = 0;
                                }
                                $totalSubYx[$subject_value['subject_id']] += $yx;
                                $totalSubJg[$subject_value['subject_id']] += $jg;
                                $totalSubdf[$subject_value['subject_id']] += $df;
                                //科目对应的key
                                $school_subject_key[$subject_value['subject_id']]['pj'] = $k;
                                $school_subject_key[$subject_value['subject_id']]['yx'] = $kl1;
                                $school_subject_key[$subject_value['subject_id']]['jg'] = $kl2;
                                $school_subject_key[$subject_value['subject_id']]['df'] = $j;
                            }
                        }
                    }
                    //单科总分（最底部)
                    if(!empty($value['subject'])){
                        foreach($value['subject'] as $subKey => $subVal){
                            if(!isset($totalSubPoint[$subKey])){
                                $totalSubPoint[$subKey] = 0;
                            }
                            $totalSubPoint[$subKey] += $subVal;
                        }
                    }
                    //得到当个学校汇总数据（最左侧）
                    if (isset($value['student']) && !empty($value['student'])) {
                        $pType = isset($scoreStd['point']) ? $scoreStd['point'] : array();
                        if(!empty($pType)){
                            foreach ($value['student'] as $pValue) {
                                $type = $zExam->_getPointType($pType,$pValue);
                                switch ($type){
                                    case 1:
                                        $ayxl += 1;  //优秀
                                        $ajgl += 1;  //及格
                                        break;
                                    case 2:
                                        $ajgl += 1;  //及格
                                        break;
                                    case 3:
                                        $adfl += 1; //低分
                                        break;
                                } 
                            }
                        }
                        $ayl = ($all_people > 0) ? sprintf('%.2f', $ayxl / $all_people * 100) : 0;
                        $ajl = ($all_people > 0) ? sprintf('%.2f', $ajgl / $all_people * 100) : 0;
                        $adl = ($all_people > 0) ? sprintf('%.2f',$adfl / $all_people * 100) : 0;
                    }
                    //得到全学校汇总(最底部)
                    $totalNum += $all_people;   //总人数
                    $totalPoint += $value['point'];
                    $totalyxPeople += $ayxl;
                    $totaljgPeople += $ajgl;
                    $totaldfPeople += $adfl;
                    //第三行开始数据
                    $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue('A' . $ii, $school_name)
                        ->setCellValue('B' . $ii, $all_people)
                        ->setCellValue('C' . $ii, $avgPoint)
                        ->setCellValue('D' . $ii, $ayl)
                        ->setCellValue('E' . $ii, $ajl)
                        ->setCellValue('F' . $ii, $adl);
                    $ii += 2;
                    
                    $new_subject_array['total'][$key]['people'] = $all_people;
                    $new_subject_array['total'][$key]['pj'] = $avgPoint;  //汇总各学校总分
                    $new_subject_array['total'][$key]['yx'] = $ayl;
                    $new_subject_array['total'][$key]['jg'] = $ajl;
                    $new_subject_array['total'][$key]['df'] = $adl;
                }
                //总分汇总 合计
                $school_avgPoint = ($totalNum > 0) ? sprintf('%.2f', $totalPoint / $totalNum) : 0;
                $s_ay1 = sprintf('%.2f', $totalyxPeople / $totalNum * 100);
                $s_aj1 = sprintf('%.2f', $totaljgPeople / $totalNum * 100);
                $s_ad1 = sprintf('%.2f', $totaldfPeople / $totalNum * 100);
                
                $subject_total_array = array();
                if (!empty($exam_subject_array)) {
                    foreach ($exam_subject_array as $sKey => $sVal) {
                        $apjf = isset($totalSubPoint[$sVal['subject_id']]) ? $totalSubPoint[$sVal['subject_id']] : 0;
                        $apj = sprintf('%.2f', $apjf / $totalNum);
                        $ayxf = isset($totalSubYx[$sVal['subject_id']]) ? $totalSubYx[$sVal['subject_id']] : 0;
                        $ayx = sprintf('%.2f', $ayxf / $totalNum * 100);
                        $ajgf = isset($totalSubJg[$sVal['subject_id']]) ? $totalSubJg[$sVal['subject_id']] : 0;
                        $ajg = sprintf('%.2f', $ajgf / $totalNum * 100);
                        $adff = isset($totalSubdf[$sVal['subject_id']]) ? $totalSubdf[$sVal['subject_id']] : 0;
                        $adf = sprintf('%.2f', $adff / $totalNum * 100);
                        $subject_total_array[$sVal['subject_id']]['pj'] = $apj;
                        $subject_total_array[$sVal['subject_id']]['yx'] = $ayx;
                        $subject_total_array[$sVal['subject_id']]['jg'] = $ajg;
                        $subject_total_array[$sVal['subject_id']]['df'] = $adf;
                        $xls_k1 = isset($school_subject_key[$sVal['subject_id']]['pj']) ? $school_subject_key[$sVal['subject_id']]['pj'] : '';
                        $xls_k2 = isset($school_subject_key[$sVal['subject_id']]['yx']) ? $school_subject_key[$sVal['subject_id']]['yx'] : '';
                        $xls_k3 = isset($school_subject_key[$sVal['subject_id']]['jg']) ? $school_subject_key[$sVal['subject_id']]['jg'] : '';
                        $xls_k4 = isset($school_subject_key[$sVal['subject_id']]['df']) ? $school_subject_key[$sVal['subject_id']]['df'] : '';
                        $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue($xls_k1 . $ii, $apj)
                        ->setCellValue($xls_k2 . $ii, $ayx)
                        ->setCellValue($xls_k3 . $ii, $ajg)
                        ->setCellValue($xls_k4 . $ii, $adf);
                    }
                }
                $objPHPExcel->setActiveSheetIndex(0)
                            ->setCellValue('A' . $ii, '合计')
                            ->setCellValue('B' . $ii, $totalNum)
                            ->setCellValue('C' . $ii, $school_avgPoint)
                            ->setCellValue('D' . $ii, $s_ay1)
                            ->setCellValue('E' . $ii, $s_aj1)
                            ->setCellValue('F' . $ii, $s_ad1);
                $cc = 3;
                $jj = 4;
                if(isset($new_subject_array['total'])){//单科成绩输出
                    foreach ($new_subject_array['total'] as $keys => $value) {
                        $people = isset($value['people']) ? $value['people'] : 0;
                        $zpj = isset($value['pj']) ? $value['pj'] : 0;
                        $zyx = isset($value['yx']) ? $value['yx'] : 0;
                        $zjg = isset($value['jg']) ? $value['jg'] : 0;
                        $zdf = isset($value['df']) ? $value['df'] : 0;
                        $table4 = $table5 = '';
                        $subject_array = isset($new_subject_array['subject_total'][$keys]) ? $new_subject_array['subject_total'][$keys] : array();
                        if(!empty($subject_array)){
                            foreach($subject_array as $sKey => $sValue){
                                $spj = isset($sValue['pj']) ? $sValue['pj'] : 0;
                                $syx = isset($sValue['yx']) ? $sValue['yx'] : 0;
                                $sjg = isset($sValue['jg']) ? $sValue['jg'] : 0;
                                $sdf = isset($sValue['df']) ? $sValue['df'] : 0;
                                $xls_k1 = isset($school_subject_key[$sKey]['pj']) ? $school_subject_key[$sKey]['pj'] : '';
                                $xls_k2 = isset($school_subject_key[$sKey]['yx']) ? $school_subject_key[$sKey]['yx'] : '';
                                $xls_k3 = isset($school_subject_key[$sKey]['jg']) ? $school_subject_key[$sKey]['jg'] : '';
                                $xls_k4 = isset($school_subject_key[$sKey]['df']) ? $school_subject_key[$sKey]['df'] : '';
                                
                                $zspj = isset($subject_total_array[$sKey]['pj']) ? $subject_total_array[$sKey]['pj'] : 0;
                                $zsyx = isset($subject_total_array[$sKey]['yx']) ? $subject_total_array[$sKey]['yx'] : 0;
                                $zsjg = isset($subject_total_array[$sKey]['jg']) ? $subject_total_array[$sKey]['jg'] : 0;
                                $zsdf = isset($subject_total_array[$sKey]['df']) ? $subject_total_array[$sKey]['df'] : 0;
                                $cspj = sprintf('%.2f', (float)$spj-(float)$zspj);
                                $csyx = sprintf('%.2f', (float)$syx-(float)$zsyx);
                                $csjg = sprintf('%.2f', (float)$sjg-(float)$zsjg);
                                $csdf = sprintf('%.2f', (float)$sdf-(float)$zsdf);
                                $objPHPExcel->setActiveSheetIndex(0)
                                ->setCellValue($xls_k1 . $jj, $cspj)
                                ->setCellValue($xls_k2 . $jj, $csyx)
                                ->setCellValue($xls_k3 . $jj, $csjg)
                                ->setCellValue($xls_k4 . $jj, $csdf);
                            }
                        }
                       $cpj = sprintf('%.2f', (float)$zpj - (float)$school_avgPoint);
                       $cyx = sprintf('%.2f', (float)$zyx - (float)$s_ay1);
                       $cjg = sprintf('%.2f', (float)$zjg - (float)$s_aj1);
                       $cdf = sprintf('%.2f', (float)$zdf - (float)$s_ad1);
                       $objPHPExcel->setActiveSheetIndex(0)
                                ->setCellValue('C' . $jj, $cpj)
                                ->setCellValue('D' . $jj, $cyx)
                                ->setCellValue('E' . $jj, $cjg)
                                ->setCellValue('F' . $jj, $cdf);
                       $ii += 2;
                       $jj += 2;
                    }
                }
                $objPHPExcel->setActiveSheetIndex(0);
                $file_nams = "优秀率统计";
                $file_nams .= ".xls";
                if (preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"])) {
                    $file_nams = urlencode($file_nams);
                    $file_nams = str_replace("+", "%20", $file_nams); // 替换空格
                }
                ob_end_clean();
                header("Content-Type: application/vnd.ms-excel;charset=utf-8");
                header("Content-Disposition: attachment; filename=" . $file_nams);
                header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
                header('Expires:0');
                header('Pragma:public');
                $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
                $objWriter->save('php://output');
                Yii::app()->end();
                spl_autoload_register(array('YiiBase', 'autoload'));
            }else{
                //没有相关信息
                echo 1;
                exit;
            }
        }else{
            //没有相关信息
            echo 1;
            exit;
        }
    }
    /**
     * 计算出xls 的标头
     * 
     * @version 1.0
     * @date 2014-01-25
     */
    protected function _getXlsTitle($num) {
        $data = array(0=>'A',1=>'B',2=>'C',3=>'D',4=>'E',5=>'F',6=>'G',7=>'H',8=>'I',9=>'J',10=>'K',11=>'L',12=>'M',13=>'N',14=>'O',15=>'P',16=>'Q',17=>'R',18=>'S',19=>'T',20=>'U',21=>'V',22=>'W',23=>'X',24=>'Y',25=>'Z');
        $d = 26;
        $z = floor($num/$d);
        $key = '';
        if($z>0){
            $y = floor($num%$d);
            if($y==0){
                $key = $data[$y].$data[$z-1];
            }else{
                $key = $data[$z-1].$data[$y];
            }
        }else{
            $key = $data[$num];
        }
        return $key;
    }
    
    /**
     * 初中分数分段统计
     * 
     * @version 1.0
     * @date 2014-01-24
     */
    public function actionInterval() {
        $this->__common();
        $this->layout = "//layouts/main_other";

        Yii::app()->clientScript->registerCssFile(THEME_CSS_URL . '/chart.css');
        Yii::app()->clientScript->registerScriptFile(STATICS_URL . "/js/Highcharts/js/highcharts.js");
        Yii::app()->clientScript->registerScriptFile(STATICS_URL . "/js/Highcharts/js/modules/exporting.js");
        Yii::app()->clientScript->registerScriptFile(THEME_JS_URL . "/chart.js");

        $exam_id = $this->request->getParam('exam_id');
        $school_code = $this->request->getParam('school_code');

        $zExam = new zExam();
        $scoreArray = $point = array();

        $exam_array = $zExam->_getExamInfo($exam_id); //考试信息
        $score_array = $zExam->_getSectionObject($exam_id); //分数段

        $zEdu = new ZEdu();
        $schoolObject = $zEdu->_getSchoolObject(); //学校信息

        $all_dfl = 0; //低分率汇总
        $photo_data = $new_photo_data = $subject_photo_data = $dataNum_photo = $school_photo = array();  //图表显示数据
        $table1 = $table2 = $table3 = $table6 = '';
        if ($score_array) {
            $scoreArray = $zEdu->_getScoreArray($score_array['score_type1'], $score_array['score_type2'], $score_array['score_type3']);//分数段
            //得到当前考试人数分数
	        if ($this->user_role_list != 1) {
	        	$point = $zExam->_getExamArrayList($school_code, $exam_id, $scoreArray,$this->user_school_list);
	        }else {
            $point = $zExam->_getExamArrayList($school_code, $exam_id, $scoreArray);
	        }
            $dfAllNum = 0;
            if (!empty($point) && !empty($point['data'])) {
                $pointTotalPeople = 0; //合计统计数
                $pointScoreArray = array();
                foreach ($point['data'] as $pKey => $pValue) {
                    $table4 = '';
                    if (!empty($point['key'])) {
                        $allNum = count($point['key']);
                        foreach ($point['key'] as $fKey => $fValue) {
                            $num = isset($pValue['data'][$fValue]) ? $pValue['data'][$fValue] : 0;
                            $table4 .= '<td align="center" class="border_d" valign="middle" ><span style="padding:0 5px;">' . $num . '</span></td>';
                            $subject_photo_data[$fKey][] = $num;  //图表显示人数
                            if(!isset($pointScoreArray[$fValue]))
                                $pointScoreArray[$fValue] = 0;
                            $pointScoreArray[$fValue] += $num;
                        }
                        //低分率
                        $dpoint_l = 0;
                        $pkey = isset($point['key'][$allNum-1]) ? $point['key'][$allNum-1] : '';
                        if(!empty($pkey)){
                            $dpoint = isset($pValue['data'][$pkey]) ? $pValue['data'][$pkey] : 0;
                            $dpoint_l = sprintf('%.2f', $dpoint / $pValue['people'] * 100);
                            $dfAllNum += $dpoint;
                        }
                        $table4 .= '<td align="center" class="border_d" valign="middle" ><span style="padding:0 5px;">' . $dpoint_l . '%</span></td>';
                    }
                    $school_name = isset($schoolObject[$pKey]) ? $schoolObject[$pKey] : '';
                    $table3 .= '<tr height="38">
                                <td align="center" class="border_d" valign="middle" ><span style="padding:0 5px;">' . $school_name . '<span></td>
                                <td align="center" class="border_d" valign="middle" ><span style="padding:0 5px;">' . $pValue['people'] . '<span></td>
                                ' . $table4 . '</tr>';

                    $pointTotalPeople += (int) $pValue['people'];
                    $photo_data[] = (int) $pValue['people'];  //图表显示人数
                    $school_photo[] = $school_name; //图表显示学校
                    //$photo_data['dataNum'][] = (int) $pValue['people'];  //图表显示人数
                    //$photo_data['categories'][] = $school_name; //图表显示学校
                    //$photo_data['lable'] = 'lable';
                    //$photo_data['unit'] = '人';
                }
                $table6 .= '<td align="center" class="border_d" valign="middle" ><span style="padding:0 5px;">' . $pointTotalPeople . '<span></td>';
                if(!empty($pointScoreArray)){
                    foreach($pointScoreArray as $aVal){
                        $table6 .= '<td align="center" class="border_d" valign="middle" ><span style="padding:0 5px;">' . $aVal . '<span></td>';
                    }
                    $dfAllbl = ($pointTotalPeople>0) ? sprintf('%.2f', $dfAllNum / $pointTotalPeople * 100) : 0;
                    $table6 .= '<td align="center" class="border_d" valign="middle" ><span style="padding:0 5px;">' . $dfAllbl . '%<span></td>';
                }
                $peopleNum = array();
                $peopleNum[] = $photo_data;
                $dataNum_photo = array_merge_recursive($peopleNum,$subject_photo_data);
                $new_photo_data['categories'] = $school_photo;
                $new_photo_data['lable'] = 'lable';
                $new_photo_data['unit'] = '人';
            }
            if (!empty($scoreArray)) {
                foreach ($scoreArray as $value) {
                    $table1 .= '<th width="87" align="center" class="border_d"></th>';
                    $table2 .= '<th width="" align="center"  valign="middle" class="border_d"><span style="padding:0 5px;">' . $value['name'] . '</span></th>';
                }
                $table2 .= '<th width="" align="center"  valign="middle" class="border_d"><span style="padding:0 5px;">低分率</span></th>';
            }
        }

        $photo_data = json_encode($photo_data);
        $this->title = '(初中)成绩分段统计';
        $this->render("interval", array(
            'exam_array'    => $exam_array,
            'table1'        => $table1,
            'table2'        => $table2,
            'table3'        => $table3,
            'table6'        => $table6,
            'scoreArray'    => $scoreArray,
            'dataNum_photo' => $dataNum_photo,
            'new_photo_data' => $new_photo_data,
            'exam_id'       => $exam_id,
            'school_id'     => $school_code
        ));
    }

    /**
     * 初中分数分段统计导出
     * 
     * @version 1.0
     * @date 2014-01-24
     */
    public function actionImport_interval() {
        $exam_id = $this->request->getParam('exam_id');
        $school_id = $this->request->getParam('school_id');
        if (!empty($exam_id)) {
            $zExam = new zExam();
            $scoreArray = $point = array();
            $exam_array = $zExam->_getExamInfo($exam_id);
            $score_array = $zExam->_getSectionObject($exam_id);
            $zEdu = new ZEdu();
            $schoolObject = $zEdu->_getSchoolObject();
            $scoreArray = $zEdu->_getScoreArray($score_array['score_type1'], $score_array['score_type2'], $score_array['score_type3']);
            //得到当前考试人数分数
	        if ($this->user_role_list != 1) {
	        	$point = $zExam->_getExamArrayList($school_id, $exam_id, $scoreArray,$this->user_school_list);
	        }else {
            $point = $zExam->_getExamArrayList($school_id, $exam_id, $scoreArray);
	        }
            if (!empty($point)) {
                spl_autoload_unregister(array('YiiBase', 'autoload'));
                include_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/extensions/PHPExcel.php');
                include_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/extensions/PHPExcel/IOFactory.php');
                $objPHPExcel = new PHPExcel();
        
                //第一行
                $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue('A1', '学校')
                        ->setCellValue('B1', '人数');
        
                $i = 2;
                $keyArray = array();
                $allNum = count($point['key']);
                foreach($point['key'] as $value){
                    $keys = self::_getXlsTitle($i);
                    $objPHPExcel->setActiveSheetIndex(0)->setCellValue($keys . 1, $value);
                    $keyArray[$value] = $keys;
                    $i++;
                }
                $keys = self::_getXlsTitle($i);
                $objPHPExcel->setActiveSheetIndex(0)->setCellValue($keys . 1, '低分率');
                $ii = 2;
                $pointTotalPeople = $all_dfl = 0;
                $pointScoreArray = array(); //汇总行
                if(!empty($point['data'])){
                    foreach($point['data'] as $skey => $svalue){
                        $school_name = isset($schoolObject[$skey])?$schoolObject[$skey]:'';
                        $pointTotalPeople += $svalue['people'];
                        $objPHPExcel->setActiveSheetIndex(0)
                            ->setCellValue('A' . $ii, $school_name)
                            ->setCellValue('B' . $ii, $svalue['people']);
                        foreach($svalue['data'] as $dk => $dv){
                            if(!isset($pointScoreArray[$dk])){
                                $pointScoreArray[$dk] = 0;
                            }
                            $pointScoreArray[$dk] += $dv;
                            $lk = isset($keyArray[$dk])?$keyArray[$dk]:'';
                            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($lk . $ii, $dv);
                        }
                        //低分率
                        $dpoint_l = 0;
                        $pkey = isset($point['key'][$allNum-1]) ? $point['key'][$allNum-1] : '';
                        if(!empty($pkey)){
                            $dpoint = isset($svalue['data'][$pkey]) ? $svalue['data'][$pkey] : 0;
                            $dpoint_l = sprintf('%.2f', $dpoint / $svalue['people'] * 100);
                            $all_dfl += $dpoint;
                        }
                        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($keys . $ii, $dpoint_l);
                        $ii++;
                    }
                }
                //最后一行
                $objPHPExcel->setActiveSheetIndex(0)
                        ->setCellValue('A'.$ii, '合计')
                        ->setCellValue('B'.$ii, $pointTotalPeople);
                if(!empty($pointScoreArray)){
                    foreach($pointScoreArray as $pKey => $pVal){
                        $lk = isset($keyArray[$pKey])?$keyArray[$pKey]:'';
                        if(!empty($lk)){
                            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($lk.$ii, $pVal);
                        }
                    }
                    $all_dfbl = ($pointTotalPeople>0) ? sprintf('%.2f', $all_dfl / $pointTotalPeople * 100) : 0;
                    $objPHPExcel->setActiveSheetIndex(0)->setCellValue($keys . $ii, $all_dfbl);
                }
                $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
                $objPHPExcel->setActiveSheetIndex(0);
                $file_nams = "分数段统计";
                $file_nams .= ".xls";
                if (preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"])) {
                    $file_nams = urlencode($file_nams);
                    $file_nams = str_replace("+", "%20", $file_nams); // 替换空格
                }
                ob_end_clean();
                header("Content-Type: application/vnd.ms-excel;charset=utf-8");
                header("Content-Disposition: attachment; filename=" . $file_nams);
                header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
                header('Expires:0');
                header('Pragma:public');
                $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
                $objWriter->save('php://output');
                Yii::app()->end();
                spl_autoload_register(array('YiiBase', 'autoload'));
                exit;
            } else {
                echo 1;
                exit;
            }
        } else {
            echo 1;
            exit;
        }
    }
    public function actionDoubleb(){
        $this->__common();
        $this->layout = "//layouts/main_other";
        Yii::app()->clientScript->registerCssFile(THEME_CSS_URL . '/chart.css');
        Yii::app()->clientScript->registerScriptFile(STATICS_URL . "/js/Highcharts/js/highcharts.js");
        Yii::app()->clientScript->registerScriptFile(STATICS_URL . "/js/Highcharts/js/modules/exporting.js");
        Yii::app()->clientScript->registerScriptFile(THEME_JS_URL . '/chart.js');
        // request 参数
        $examID = $this->request->getParam('exam_id');
        $schoolID = $this->request->getParam('school_id'); 
        $ajaxType = $this->request->getParam('type'); 
        $exportExcel = $this->request->getParam('export_excel');
        $where = '"{{student}}"."exam_id"= \''.$examID.'\' AND "{{student}}"."statis" = \'T\'';
        if($schoolID){
             $where = ' "{{student}}"."exam_id" =\''.$examID.'\' AND "{{student}}"."school_id" =\''.$schoolID.'\' AND "{{student}}"."statis" = \'T\'';
        }
        $db = Yii::app()->db;
        $schoolData = array();
        // 考试科别
        $sql = 'SELECT  distinct "disciplin_code"   FROM "{{student}}" WHERE '.$where;
        $disciplinCodeRows = $db->createCommand($sql)->queryAll();
        $disciplinCodes = array();
        if($disciplinCodeRows){
            foreach($disciplinCodeRows AS $k=>$v){
                $disciplinCodes[$v['disciplin_code']] = $v['disciplin_code'];
            }
        }
        
        // 科别科目 
        $examDisciplin = array();
        $subjectList = array();
        if($disciplinCodes){
            $disciplinIDStrs = implode("','", $disciplinCodes);
            $sql = 'SELECT d."disciplin_code",ds."disciplin_id",ds."subject_id",s."subject_name" 
                    FROM "{{disciplin_subject}}" ds 
                    LEFT JOIN "{{disciplin}}" d ON ds."disciplin_id"=d."disciplin_id"
                    LEFT JOIN "{{subject}}" s ON s."subject_id" = ds."subject_id"
                    WHERE d."disciplin_code" in(\''.$disciplinIDStrs.'\')';
            $dpSubjectRows = $db->createCommand($sql)->queryAll();
            if($dpSubjectRows){
                foreach($dpSubjectRows AS $k=>$v){
                    if($v['subject_id']){
                        $examDisciplin[$v['disciplin_code']][$v['subject_id']] = $v; 
                        $subjectList[$v['subject_id']] = $v['subject_name'];
                    }
                }
            }
        }
        
        
        // 要统计的学校
    	$schoolWhere = '"exam_id"=\''.$examID.'\'';
        if($schoolID){
             $schoolWhere = ' "exam_id"=\''.$examID.'\' AND es."school_id"=\''.$schoolID.'\'';
        }
        $examSchoolList = array();
        $sql = 'SELECT es."school_id",s."school_name" FROM "{{exam_school}}" es 
                LEFT JOIN "{{school}}" s ON es."school_id"=s."school_id"
                WHERE '.$schoolWhere;
        $schoolRows = $db->createCommand($sql)->queryAll();
        if($schoolRows){
            foreach($schoolRows AS $k=>$v){
                $examSchoolList[$v['school_id']] = $v['school_name'];
            }
        }
        
        // 个学校总参考人数
        if($examID){
            $sql = 'SELECT COUNT(*) "num","school_id" FROM "{{student}}" WHERE '.$where.' GROUP BY "school_id"';
            $schoolNums = $db->createCommand($sql)->queryAll();
            if($schoolNums){
                foreach($schoolNums AS $k=>$v){
                    $schoolData[$v['school_id']]['studentNum'] = $v['num'];
                }
            }
        }
        
        // 各科参考人数
        $sql = 'SELECT COUNT(*) "num","disciplin_code","school_id" FROM "{{student}}" WHERE '.$where.'  GROUP BY "disciplin_code","school_id" ';
        $dpStudentNumRows = $db->createCommand($sql)->queryAll();
        $dpStudnetNum = array();
        if($dpStudentNumRows){
            foreach($dpStudentNumRows AS $k=>$v){
                if(isset($examDisciplin[$v['disciplin_code']])){
                    foreach ($examDisciplin[$v['disciplin_code']] AS $sk=>$sv){
                        $subjectStudentNum = isset($schoolData[$v['school_id']]['subjectStudentNum'][$sk])?$schoolData[$v['school_id']]['subjectStudentNum'][$sk]:0;
                        $schoolData[$v['school_id']]['subjectStudentNum'][$sk] = $subjectStudentNum+$v['num'];
                    }
                }
                $dpStudnetNum[$v['disciplin_code']] = 1;
            }
        }
        
        $subjectBGrads = array();
        // 各科达B分数
        if($subjectList){
            $subjectIDs = implode(',', array_keys($subjectList));
            $sql = 'SELECT "subject_id","score" FROM "{{point_grading}}" WHERE "exam_id"=\''.$examID.'\' AND "grading_id"=4 AND "subject_id" in ('.$subjectIDs.')';
            $subjectGradRows = $db->createCommand($sql)->queryAll();
            if($subjectGradRows){
                foreach($subjectGradRows AS $k=>$v){
                    $subjectBGrads[$v['subject_id']] = $v['score'];
                }
            }
        }
        
        // 各学校各科达B人数
        if($subjectList){
            foreach ($subjectList AS $subK => $subV) {
                if (isset($subjectBGrads[$subK])) {
                    $sql = 'SELECT count(*) "num","{{student}}"."school_id" FROM "{{point}}"
                            LEFT JOIN "{{student}}" ON "{{student}}"."student_id" = "{{point}}"."student_id"
                            WHERE '.$where.' AND "{{point}}"."subject_id"='.$subK .' AND "{{point}}"."score">=' . $subjectBGrads[$subK] . ' 
                            GROUP BY "{{student}}"."school_id"';
                    $subjectBnum = $db->createCommand($sql)->queryAll();
                    if ($subjectBnum) {
                        foreach ($subjectBnum AS $v) {
                            $schoolData[$v['school_id']]['subjectStudentBNum'][$subK] = $v['num'];
                        }
                    }
                }
            }
            // 要统计的学校
            $schoolWhere = ' p."exam_id"=\''.$examID.'\' AND s."statis" = \'T\'';
            if($schoolID){
                $schoolWhere = ' p."exam_id"=\''.$examID.'\' AND p."school_id"=\''.$schoolID.'\' AND s."statis" = \'T\'';
            }
            // 双B
            $sql = 'SELECT count(p."student_id") "num",ds."disciplin_id",p."school_id" FROM "{{point}}" p
                            LEFT JOIN "{{student}}" s on p."student_id"=s."student_id"
                            LEFT JOIN "{{disciplin}}" d on d."disciplin_code"=s."disciplin_code"
                            LEFT JOIN "{{disciplin_subject}}" ds on ds."subject_id"=p."subject_id" AND d."disciplin_id"=ds."disciplin_id"
                            LEFT JOIN "{{point_grading}}" pg ON p."subject_id"=pg."subject_id" AND p."exam_id"=pg."exam_id" AND pg."grading_id"=4
                            WHERE '.$schoolWhere.' AND p."score">=pg."score" AND ds."subject_id">0 AND pg."subject_id">0
                            GROUP by ds."disciplin_id",p."student_id",p."school_id"
                            HAVING count(p."student_id")>1';
            $subjectBnum = $db->createCommand($sql)->queryAll();
            if($subjectBnum){
                foreach($subjectBnum AS $v){
                    $num = isset($schoolData[$v['school_id']]['subjectStudentDBNum'])?$schoolData[$v['school_id']]['subjectStudentDBNum']:0;
                    $schoolData[$v['school_id']]['subjectStudentDBNum'] = $num+1;
                }
            }
        }
        if($exportExcel==1){
            spl_autoload_unregister(array('YiiBase', 'autoload'));
			include_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/extensions/PHPExcel.php');
			include_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/extensions/PHPExcel/IOFactory.php');

			$objPHPExcel = new PHPExcel();
            spl_autoload_register(array('YiiBase', 'autoload'));
            $sheet = $objPHPExcel->setActiveSheetIndex(0);
            $sheet->setCellValue('A1', '学校');
            $sheet->setCellValue('B1', '人数');
            $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
            $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
            $chr = 3;
            foreach($subjectList as $sk =>$sv){
               $colName = ZCommon::numToExcelColName($chr);
               $sheet->setCellValue($colName.'1', '选'.$sv);
               $objPHPExcel->getActiveSheet()->getColumnDimension($colName)->setWidth(15);
               $chr++;
            }
            $colName = ZCommon::numToExcelColName($chr);
            $sheet->setCellValue($colName.'1', '2B人数');$chr++;
            $objPHPExcel->getActiveSheet()->getColumnDimension($colName)->setWidth(15);
            
            $colName = ZCommon::numToExcelColName($chr);
            $sheet->setCellValue($colName.'1', '2B率');$chr++;
            $objPHPExcel->getActiveSheet()->getColumnDimension($colName)->setWidth(15);
            
            foreach($subjectList as $sk =>$sv){
               $colName = ZCommon::numToExcelColName($chr);
               $sheet->setCellValue($colName.'1', $sv);
               $objPHPExcel->getActiveSheet()->getColumnDimension($colName)->setWidth(15);
               $chr++;
               $colName = ZCommon::numToExcelColName($chr);
               $sheet->setCellValue($colName.'1', $sv.'率%');
               $objPHPExcel->getActiveSheet()->getColumnDimension($colName)->setWidth(15);
               $chr++;
            }
            $i = 2;
            foreach ($schoolData as $school_id=>$schoolB) {
                $pepole_num = isset($schoolB['studentNum'])?$schoolB['studentNum']:0;
                $sheet->setCellValue('A' . $i,  isset($examSchoolList[$school_id])?$examSchoolList[$school_id]:'');
                $sheet->setCellValue('B' . $i, $pepole_num);
                $chr = 3;
                foreach($subjectList as $sk =>$sv){
                    $colName = ZCommon::numToExcelColName($chr);
                    $sheet->setCellValue($colName.$i, isset($schoolB['subjectStudentNum'][$sk])?$schoolB['subjectStudentNum'][$sk]:0);
                    $chr++;
                }
                $totalB = isset($schoolB['subjectStudentDBNum'])?$schoolB['subjectStudentDBNum']:'0';
                $dbP = $pepole_num?round($totalB*100/$pepole_num,2):0;
                $sheet->setCellValue(ZCommon::numToExcelColName($chr).$i, $totalB);$chr++;
                $sheet->setCellValue(ZCommon::numToExcelColName($chr).$i, $dbP);$chr++;
                foreach($subjectList as $sk =>$sv){
                    $subject_total_num = isset($schoolB['subjectStudentNum'][$sk])?$schoolB['subjectStudentNum'][$sk]:0;
                    $subject_totalB_num = isset($schoolB['subjectStudentBNum'][$sk])?$schoolB['subjectStudentBNum'][$sk]:0;
                    $sheet->setCellValue(ZCommon::numToExcelColName($chr).$i, $subject_totalB_num);
                    $chr++;
                    $sheet->setCellValue(ZCommon::numToExcelColName($chr).$i, $subject_total_num?round($subject_totalB_num*100/$subject_total_num,2):0);
                    $chr++;
                }
                $i++;
            }
            $objPHPExcel->setActiveSheetIndex(0);
            $file_nams = "选修课双B及单科达B率导出";
            $file_nams .= ".xls";
            if (preg_match("/MSIE/", $_SERVER["HTTP_USER_AGENT"])) {
				$file_nams = urlencode($file_nams);
				$file_nams = str_replace("+", "%20", $file_nams); // 替换空格
			}
			ob_end_clean();
			header("Content-Type: application/vnd.ms-excel;charset=utf-8");
			header("Content-Disposition: attachment; filename=" . $file_nams);
			header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
			header('Expires:0');
			header('Pragma:public');

			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output');

			Yii::app()->end();
			spl_autoload_register(array('YiiBase', 'autoload'));
        }
        $school_data = array();
        if(!empty($schoolData)){
            foreach ($schoolData AS $school_id => $schoolB) {
				$pepole_num = isset($schoolB['studentNum'])?$schoolB['studentNum']:0;
				$totalB = isset($schoolB['subjectStudentDBNum'])?$schoolB['subjectStudentDBNum']:'0';
				$school_data[] = $pepole_num?round($totalB*100/$pepole_num,2):0;
				foreach($subjectList AS $k=>$v){
					$subject_total_num = isset($schoolB['subjectStudentNum'][$k])?$schoolB['subjectStudentNum'][$k]:0;
					$subject_totalB_num = isset($schoolB['subjectStudentBNum'][$k])?$schoolB['subjectStudentBNum'][$k]:0;
					$school_data[] = $subject_total_num?round($subject_totalB_num*100/$subject_total_num,2):0;
				}
			}
        }
        if( $ajaxType == "ajax" ){
        	echo json_encode($school_data);
        	exit;
        }
         
        $this->title = '选修课双B及单科达B率';
        $this->render('doubleb_list',array(
            'schoolData'            => $schoolData,
            'subjectList'           => $subjectList,
            'schoolList'            => $examSchoolList,
            'rSchoolID'             => $schoolID,
            'rExamID'               => $examID
        ));
    }
    
    
    public function actionDoublebindex(){  
        $this->__common();

        $zExam = new zExam();
        $examArray = $zExam->_getExamObject($this->exam_id, $this->user_role_list);

        
        
        $this->title = '选修课双B及单科达B率';
        $this->render('doubleb_index',array(
            'examList' => $examArray
        ));
    } 
    
    /**
     * 得到学校信息
     * 
     * @version 1.0
     * @date 2013-12-31
     */
    public function actionAjax_get_school() {

    	$this->__common();
    	$school_ids = $this->user_school_list;
        $exam_id = $this->request->getParam('exam_id');

        $list = '<option value="">请选择</option>';
        if ($exam_id > 0) {
            $zEdu = new ZEdu();

            $zExam = new zExam();
            $school_array = $zExam->_getExamSchoolArray($exam_id, $zEdu, $school_ids);
            if (!empty($school_array)) {
                foreach ($school_array as $value) {
                    $list .= "<option value='" . $value['school_id'] . "'>" . $value['school_name'] . "</option>";
                }
            }
        }
        echo $list;
    }
    /**
     * 不参加统计规则统计 
     */
    public function actionNojoincollect(){
        $this->__common();
		$this->title = '园区小题分设置';
        $db = Yii::app()->db;
        if(empty($_POST['submit'])){
            // 考试
            $examSql = "SELECT * FROM \"{{exam}}\" WHERE \"is_del\"=0";
            $examAll = $db->createCommand($examSql)->queryAll();
            
            // 统计规则
            $roleSql = " SELECT * FROM \"{{nojoinrule}}\" WHERE \"is_del\"=0 ";
            $roleAll = $db->createCommand($roleSql)->queryAll();
            
            // 已经使用的不参加统计规则
            $this->render('nojoin_collect',array(
                'title'=>'园区小题分汇总',
                'examAll'=>$examAll,
                'roleAll'=>$roleAll
            ));
            exit;
        }
        $examID = $this->request->getParam('exam_id');
        $noJoinID = $this->request->getParam("no_join_id");
        
        // 检查考试是否存在
        $sql = ' SELECT "exam_id" FROM　"{{exam}}" WHERE "exam_id" = '."'".$examID."'".' AND "is_del"=0';
        $examExist = $db->createCommand($sql)->queryRow();
        if(!$examExist){
			$this->frameAjaxMessage(null, '请选择考试项目');
			exit;
        }
        
        // 统计规则是否存在
        if($noJoinID != 0){
            $sql = "SELECT \"id\" FROM \"{{nojoinrule}}\" WHERE \"id\"='{$noJoinID}'";
            $noJoinRow = $db->createCommand($sql)->queryRow();
            if(!$noJoinRow){
                $this->frameAjaxMessage(null, '统计规则不存在');
				exit;
            }
        }
		$clearSql = 'update "{{student}}" set  "hxf"=0, "hxkgf"=0, "hxzgf"=0, "swf" =0, "swkgf" =0, "swzgf" =0, "sxf" =0, "sxfjf" =0, "sxjdf" =0, "sxtkf"  =0, "wlf" =0, "wlkgf" =0, "wlzgf" =0, "ywf"=0 , "ywfjf" =0, "ywkgf" =0, "ywzgf"=0 , "ywzwf" =0, "yyf" =0, "yykgf" =0, "yyzgf" =0, "yyzwf" =0, "zzf" =0, "zzkgf" =0, "zzzgf"=0,"yswzf"=0,"yswzfhfjf"=0,"lsf"=0 where "exam_id"='.$examID;
        $db->createCommand($clearSql)->execute();
        // 汇总统计
        $import = new ZPScoreImport('');
        $m = $import->statisScore($examID);
        
        // 重置不参加统计字段
        $resetSql = "UPDATE \"{{student}}\" SET \"statis\"='T' WHERE \"exam_id\"='{$examID}'";
        $db->createCommand($resetSql)->execute();
        
        // 按照统计规则设置是否统计字段值
        $noJoinSql =  "SELECT \"addwheres\" FROM \"{{nojoinrule_detail}}\" WHERE \"join_id\"='{$noJoinID}' AND \"is_del\"=0 AND \"status\"=1";
        $noJoinDetailRow = $db->createCommand($noJoinSql)->queryAll();

        if($noJoinDetailRow){
            foreach($noJoinDetailRow AS $k=>$v){
                $wheres = !empty($v['addwheres']) ? ' AND ('.$v['addwheres'].')' : '';
                $wheres =  trim($wheres,'AND');
                $wheres =  trim($wheres,'OR');
                $upsql  = 'UPDATE "{{student}}" SET "statis" =\'F\' WHERE 1=1 AND "exam_id"  = '.$examID.$wheres;
			
                $db->createCommand($upsql)->execute();
            }
        }
        // 记录考试使用的不参加统计规则
        $resetSql = "UPDATE \"{{exam}}\" SET \"statis_rule\"='{$noJoinID}' WHERE \"exam_id\"='{$examID}'";
        $db->createCommand($resetSql)->execute();
        $this->frameAjaxMessage(null, '汇总完成');
        exit;
    }
 
    public function actionExamrule(){
        $exam_id = $this->request->getParam('exam_id');
        $sql = 'SELECT "statis_rule","name" FROM "{{exam}}" e
                LEFT JOIN "{{nojoinrule}}" n ON e."statis_rule" = n."id"
                WHERE "exam_id"='."'{$exam_id}'";
        $exam = Yii::app()->db->createCommand($sql)->queryRow();
        if(!$exam || $exam['statis_rule']==-1){
            echo "还没进行统计";
            exit;
        }elseif($exam['statis_rule']==0){
            echo "已统计过，但未使用任何统计规则";
            exit;
        }
        echo "已使用(".$exam['name'].")统计过";
    }
    /*private function _questionPointCollect($examID){
        $examSubjects = ExamData::_getExamSubject($examID);
        if(!$examSubjects){
            return true;
        }
        $subjects = array();
        foreach($examSubjects AS $v){
            $subjects[] = array('id'=>$v['subject_id'],'code'=>SmallProblem::pinyin($v['subject_name']).'f');
        }
        return true;
        //var_dump($subjects);exit;
        $import = new ZPScoreImport('');
        $import->statisScore($examID,$subjects);
        return true;
        $conn = Yii::app()->db;
        // 学生成绩
        
        // 小题分汇总设置
        foreach($examSubjects AS $subject){
            $upsql = null;
            $subjectID = $subject['subject_id'];
            $SubjectCode = SmallProblem::pinyin($subject['subject_name']).'f';
            
            // 学生表是否缓存科目汇总分数
            $checkrowsql = 'select count(column_name) from cols where table_name=\'{{student}}\' and column_name=\''.$SubjectCode.'\'';
            $rowrow = Yii::app()->db->createCommand($checkrowsql)->queryRow();
            $studentCacheState = $rowrow['COUNT(COLUMN_NAME)'];
            
            // 科目下的所有小题
            $subjectQuestionSql = "SELECT * FROM \"{{question_sum}}\" WHERE \"subject_id\"='{$subjectID}' AND \"exam_id\"='{$examID}'";
            $subjectQuestions = $conn->createCommand($subjectQuestionSql)->queryAll();
             
            if(!$subjectQuestions)      #L 科目下小题未设置不进行汇总
                continue;
            $TypeColl = array();        #V 题型汇总
            $codeColl = array();        #V 题分汇总
            if($subjectQuestions){
                foreach($subjectQuestions AS  $questionIni){
                    if($questionIni['collect_mode'] == 1){
                        $TypeColl[$questionIni['collect_fields']] = $questionIni['collect_questions'];
                    }else if($questionIni['collect_mode'] == 2){
                        $codeColl[$questionIni['collect_fields']] = empty($questionIni['collect_question'])?array():explode(',', $questionIni['collect_question']);
                    }
                }
            }
            
            if(empty($TypeColl) && empty($codeColl))    #L 科目小题分汇总未设置不进行汇总
                continue;
            
            //判断当前题号是否存在
            $quesNameTypeMap = array();#汇总方式
            $teacher_numsql = 'SELECT * FROM "{{teacher_num}}" WHERE "exam_id"=' . $examID . ' AND "subject_id"=' . $subjectID;
            $teacher_numdata = $conn->createCommand($teacher_numsql)->queryAll();
            foreach($teacher_numdata as $tValue){
                $quesNameTypeMap[$tValue['id']] = $tValue['num_type'];
            }
            
            // 学生科目成绩
            $studentPointSql = "SELECT \"id\",\"number\",\"sub_point\",\"student_id\" 
                                FROM \"{{point}}\" WHERE \"exam_id\"='{$examID}' 
                                AND \"subject_id\"='{$subjectID}'";
            $studentPoints = $conn->createCommand($studentPointSql)->queryAll();
            
            
             //var_dump($studentPoints);exit;
            foreach($studentPoints AS $point){  #L 成绩汇总
                if(!$point['sub_point'])
                    continue;
                $subPoints = unserialize($point['sub_point']);
                $studentCollectScore = null;
                $studentCollectScore[$SubjectCode] = 0;
                //var_dump($codeColl);exit;
                foreach($subPoints AS $questionID=>$questionValue){
                    foreach($TypeColl AS $tck=>$tcv){
                        if($quesNameTypeMap[$questionID] == $tcv){
                            $studentCollectScore[$tck] = isset($studentCollectScore[$tck])?$studentCollectScore[$tck]:0;
                            $studentCollectScore[$tck] += floatval($questionValue);
                            $studentCollectScore[$SubjectCode] += floatval($questionValue);
                        }
                    }
                    foreach($codeColl AS $cck=>$ccv){
                        if(in_array($questionID, $ccv)){
                            $studentCollectScore[$cck] = isset($studentCollectScore[$cck])?$studentCollectScore[$cck]:0;
                            $studentCollectScore[$cck] += floatval($questionValue);
                            $studentCollectScore[$SubjectCode] += floatval($questionValue);
                        }
                    }
                }
                $studentID = $point['student_id'];
                $upsql .= "UPDATE \"{{point}}\" SET  \"score\"=$studentCollectScore[$SubjectCode];
                ";
                if($studentCacheState==1 && !empty($studentCollectScore)){
                        $setSql = "";
                        foreach($studentCollectScore AS $csk=>$csv){
                            $setSql .= " \"{$csk}\"='{$csv}',";
                        }
                        if(in_array($SubjectCode, array("ywf","sxf",'yyf')) && isset($studentCollectScore[$SubjectCode])){
                            $setSql .= " \"yswzf\" = \"yswzf\" + {$studentCollectScore[$SubjectCode]} , \"yswzfhfjf\" = \"yswzfhfjf\" + {$studentCollectScore[$SubjectCode]} ,";
                        }
                        if(in_array($SubjectCode, array("sxfjf","ywfjf")) && isset($studentCollectScore[$SubjectCode])){
                            $setSql .= " \"yswzfhfjf\" = \"yswzfhfjf\" + {$studentCollectScore[$SubjectCode]} ,";
                        }
                        if(isset($u['coll_score'][$SubjectCode])){
                            $setSql .= "\"score\"=\"score\"+{$studentCollectScore[$SubjectCode]} ,";
                        }
                        if(!$setSql)
                            continue;
                        $setSql = trim($setSql,',');
                        $upsql .= "UPDATE \"exm_student\" SET {$setSql} WHERE \"student_id\"='{$studentID}';
                        ";
                }
            }
            //echo $upsql;exit;
            if($upsql){
                $upsql = "  DECLARE
                            BEGIN
                            {$upsql}
                            END;";
                $conn->createCommand($upsql)->execute();
                unset($upsql);
            }
            
        }
    }
    */ 
    /**
     * 得到科目id
     * 
     * @version 1.0
     * @date 2014-03-01
     */
    protected function _getDBnum($exam_subject_array) {
        //解决分数问题对应的科目id（前提科目名称必须对应）
        $pointObject = array(
            '语文' => 'ywf',
            '数学' => 'sxf',
            '英语' => 'yyf',
            '外语' => 'yyf',
            '物理' => 'wlf',
            '化学' => 'hxf',
            '生物' => 'swf',
            '历史' => 'lsf',
            '政治' => 'zzf',
            '地理' => 'dlf'
        );
        $subjectObject = array();
        if (!empty($exam_subject_array)) {
            foreach ($exam_subject_array as $key => $value){
                $skey = isset($pointObject[$value['subject_name']]) ? $pointObject[$value['subject_name']] : '';
                if(!empty($skey)){
                    $subjectObject[$value['subject_id']]  = $skey;
                }
            }
        }
        return $subjectObject;
    }
}